﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace IntoTheme.Controls
{
    /// <summary>
    /// 按照步骤 1a 或 1b 操作，然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
    ///
    /// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
    /// 元素中:
    ///
    ///     xmlns:MyNamespace="clr-namespace:IntoTheme.Controls"
    ///
    ///
    /// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
    /// 元素中:
    ///
    ///     xmlns:MyNamespace="clr-namespace:IntoTheme.Controls;assembly=IntoTheme.Controls"
    ///
    /// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用，
    /// 并重新生成以避免编译错误:
    ///
    ///     在解决方案资源管理器中右击目标项目，然后依次单击
    ///     “添加引用”->“项目”->[浏览查找并选择此项目]
    ///
    ///
    /// 步骤 2)
    /// 继续操作并在 XAML 文件中使用控件。
    ///
    ///     <MyNamespace:ScriptBtn/>
    ///
    /// </summary>
    public class ScriptBtn : Button
    {
        static ScriptBtn()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ScriptBtn), new FrameworkPropertyMetadata(typeof(ScriptBtn)));
        }

        public bool IsChecked
        {
            get { return (bool)GetValue(IsCheckedProperty); }
            set { SetValue(IsCheckedProperty, value); }
        }

        public static readonly DependencyProperty IsCheckedProperty =
            DependencyProperty.Register("IsChecked", typeof(bool), typeof(ScriptBtn), new PropertyMetadata(null));

        public string State
        {
            get { return (string)GetValue(StateProperty); }
            set { SetValue(StateProperty, value); }
        }

        public static readonly DependencyProperty StateProperty =
            DependencyProperty.Register("State", typeof(string), typeof(ScriptBtn), new PropertyMetadata(null));

        public bool SelfLockingState
        {
            get { return (bool)GetValue(SelfLockingStateProperty); }
            set { SetValue(SelfLockingStateProperty, value); }
        }

        public static readonly DependencyProperty SelfLockingStateProperty =
            DependencyProperty.Register("SelfLockingState", typeof(bool), typeof(ScriptBtn), new PropertyMetadata(null));

        public bool PressedChangeBackground
        {
            get { return (bool)GetValue(PressedChangeBackgroundProperty); }
            set { SetValue(PressedChangeBackgroundProperty, value); }
        }

        public static readonly DependencyProperty PressedChangeBackgroundProperty =
            DependencyProperty.Register("PressedChangeBackground", typeof(bool), typeof(ScriptBtn), new PropertyMetadata(true));

        public ImageBrush NormalIcon
        {
            get { return (ImageBrush)GetValue(NormalIconProperty); }
            set { SetValue(NormalIconProperty, value); }
        }

        public static readonly DependencyProperty NormalIconProperty =
            DependencyProperty.Register("NormalIcon", typeof(ImageBrush), typeof(ScriptBtn), new PropertyMetadata(null));

        public ImageBrush DisableIcon
        {
            get { return (ImageBrush)GetValue(DisableIconProperty); }
            set { SetValue(DisableIconProperty, value); }
        }

        public static readonly DependencyProperty DisableIconProperty =
           DependencyProperty.Register("DisableIcon", typeof(ImageBrush), typeof(ScriptBtn), new PropertyMetadata(null));

        public ImageBrush CheckIcon
        {
            get { return (ImageBrush)GetValue(CheckIconProperty); }
            set { SetValue(CheckIconProperty, value); }
        }

        public static readonly DependencyProperty CheckIconProperty =
            DependencyProperty.Register("CheckIcon", typeof(ImageBrush), typeof(ScriptBtn), new PropertyMetadata(null));


        public CornerRadius CornerRadius
        {
            get { return (CornerRadius)GetValue(CornerRadiusProperty); }
            set { SetValue(CornerRadiusProperty, value); }
        }

        public static readonly DependencyProperty CornerRadiusProperty =
            DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(ScriptBtn), new PropertyMetadata(new CornerRadius(0)));


        public Brush MouseOverForeground
        {
            get { return (Brush)GetValue(MouseOverForegroundProperty); }
            set { SetValue(MouseOverForegroundProperty, value); }
        }

        public static readonly DependencyProperty MouseOverForegroundProperty =
            DependencyProperty.Register("MouseOverForeground", typeof(Brush), typeof(ScriptBtn), new PropertyMetadata());


        public Brush MousePressedForeground
        {
            get { return (Brush)GetValue(MousePressedForegroundProperty); }
            set { SetValue(MousePressedForegroundProperty, value); }
        }

        public static readonly DependencyProperty MousePressedForegroundProperty =
            DependencyProperty.Register("MousePressedForeground", typeof(Brush), typeof(ScriptBtn), new PropertyMetadata());


        public Brush MouseOverBorderbrush
        {
            get { return (Brush)GetValue(MouseOverBorderbrushProperty); }
            set { SetValue(MouseOverBorderbrushProperty, value); }
        }

        public static readonly DependencyProperty MouseOverBorderbrushProperty =
            DependencyProperty.Register("MouseOverBorderbrush", typeof(Brush), typeof(ScriptBtn), new PropertyMetadata());


        public Brush MouseOverBackground
        {
            get { return (Brush)GetValue(MouseOverBackgroundProperty); }
            set { SetValue(MouseOverBackgroundProperty, value); }
        }

        public static readonly DependencyProperty MouseOverBackgroundProperty =
            DependencyProperty.Register("MouseOverBackground", typeof(Brush), typeof(ScriptBtn), new PropertyMetadata());


        public Brush MousePressedBackground
        {
            get { return (Brush)GetValue(MousePressedBackgroundProperty); }
            set { SetValue(MousePressedBackgroundProperty, value); }
        }

        public static readonly DependencyProperty MousePressedBackgroundProperty =
            DependencyProperty.Register("MousePressedBackground", typeof(Brush), typeof(ScriptBtn), new PropertyMetadata());

        [DefaultValue(false)]
        public bool PlayAnimation
        {
            get { return (bool)GetValue(PlayAnimationProperty); }
            set { SetValue(PlayAnimationProperty, value); }
        }

        public static readonly DependencyProperty PlayAnimationProperty =
            DependencyProperty.Register("PlayAnimation", typeof(bool), typeof(ScriptBtn), new PropertyMetadata(null));

        protected override void OnMouseEnter(MouseEventArgs e)
        {
            Keyboard.Focus(this);
            base.OnMouseEnter(e);
        }
    }
}
